package com.sheenhan.gdemo.ui.main

import android.annotation.SuppressLint
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.sheenhan.gdemo.R
import com.sheenhan.gdemo.databinding.MainFragmentBinding
import com.sheenhan.gdemo.model.GDModel
import com.amap.api.maps.model.MyLocationStyle


class MainFragment : Fragment() {

    companion object {
        fun newInstance() = MainFragment()
    }

    lateinit var binding: MainFragmentBinding
    private lateinit var viewModel: MainViewModel
    lateinit var gdModel: GDModel
    override fun onCreateView(inflater: LayoutInflater , container: ViewGroup? , savedInstanceState: Bundle?): View {
        binding = DataBindingUtil.inflate(inflater , R.layout.main_fragment , container , false)
        return binding.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        gdModel = GDModel(binding.map)
        lifecycle.addObserver(gdModel)
        binding.map.onCreate(savedInstanceState)
        gdModel.data.observe(viewLifecycleOwner) {
            binding.text.text = it + "米"
        }
        binding.btn.setOnClickListener {
            gdModel.juli()
        }


    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        binding.map.onSaveInstanceState(outState)
    }

}